
package dt.htwk.core;

/**
 *	@project:	note2go
 *	@author:	D.Toepel
 *	@version:	2009-08-04
 *	@note:		---
 *	
 *	Copyright (C) 2009  D.Toepel <de.dtools> {at} <gmail> {dot} <com>
 *	
 *	This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *	
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 */

import java.text.*;
import java.util.*;
import javax.swing.*;

/**
 * Ausfuehren zeitbedingter Methoden
 * @author daniel
 *
 */
public class KCTimer extends TimerTask {

	private KCStatusBar kCStatusBar;
	private Integer id;
	
	public KCTimer(KCStatusBar kCStatusBar, Integer id){
		this.kCStatusBar = kCStatusBar;
		this.id = id;
	}
	
	public void run(){
		switch (id) {
		case 0:
			setLabelText(getTimeString());
			break;

		default: //
			break;
		}
	}
	
	private String[] getTimeString(){
		Date d = new Date();  
		DateFormat dDate,dTime;  
		dDate = DateFormat.getDateInstance(DateFormat.MEDIUM);
		dTime = DateFormat.getTimeInstance(DateFormat.MEDIUM);
		String[] out =  {dTime.format(d),dDate.format(d)}; 
		return out; 
	}
	
	private void setLabelText(final String[] output){
		Runnable r = new Runnable(){
			public void run() {
				kCStatusBar.setTime(output);
			}	
		};
		SwingUtilities.invokeLater(r);
	}

}
